package com.microservice.salmon.oauth.controller;

import com.microservice.salmon.oauth.service.MenuService;
import com.microservice.salmon.oauth.service.rbac.ShopRbacService;
import com.salmon.common.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 菜单操心相关类
 * </p>
 *
 * @author 王洪庆 2019-01-03 10:05
 */
@RestController
@Api(tags = "菜单操作服务", description = "提供系统菜单操作功能")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @Autowired
    private ShopRbacService shopRbacService;

    @GetMapping("/obtain/menuInfo/{loginName}")
    @ApiOperation("根据登录名获取用户对应的权限菜单-返回树形菜单[后台管理端]")
    @ApiImplicitParam(name = "loginName", value = "系统用户登录名")
    public ApiResponse obtainMenuByLoginName(@PathVariable(name = "loginName") String loginName) {
        return ApiResponse.ofSuccess(menuService.obtainMenuTreeByLoginName(loginName));
    }

    @GetMapping("/shop/menu/{roleId}/{shopId}")
    @ApiOperation("根据店铺人员的登录名获权限菜单-返回树形列表菜单[店铺管理端]")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID"),
            @ApiImplicitParam(name = "shopId", value = "店铺ID")
    })
    public ApiResponse obtainShopMenuByUser(@PathVariable("roleId") Integer roleId, @PathVariable("shopId") Integer shopId) {
        return ApiResponse.ofSuccess(shopRbacService.obtainTreeMenu(roleId, shopId));
    }
}
